package com.ruoyi.web.controller.report;

import com.ruoyi.balanceReturn.domain.HouseReturnT;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.data.MD5;
import com.ruoyi.moneyFlowQuery.domain.HouseMoneyFlowT;
import com.ruoyi.moneyFlowQuery.service.IHouseMoneyFlowTService;
import com.ruoyi.project.domain.HouseProjectT;
import com.ruoyi.returnQuery.service.IHouseReturnQueryTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 返还Controller
 * 
 * @author lijie
 * @date 2023-05-04
 */
@RestController
@RequestMapping("/report/moneyFlow")
public class HouseMoneyFlowTController extends BaseController
{
    @Autowired
    private IHouseMoneyFlowTService houseMoneyFlowTService;

    /**
     * 查询返还列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseMoneyFlowT houseMoneyFlowT)
    {
        startPage();
        List<HouseMoneyFlowT> list = houseMoneyFlowTService.selectHouseMoneyFlowTList(houseMoneyFlowT);
        if (list.size()!=0) {
            if (getDataTableSumJudge(list)) {
                HouseMoneyFlowT houseMoneyFlowVO = houseMoneyFlowTService.selectHouseMoneyFlowSum(houseMoneyFlowT);
                houseMoneyFlowVO.setAreaName("合计");
                list.add(houseMoneyFlowVO);
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出返还列表
     */
    @Log(title = "导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseMoneyFlowT houseMoneyFlowT)
    {
        List<HouseMoneyFlowT> list = houseMoneyFlowTService.selectHouseMoneyFlowTList(houseMoneyFlowT);
        if(getDataTableSumJudge(list)){
            HouseMoneyFlowT houseMoneyFlowVO = houseMoneyFlowTService.selectHouseMoneyFlowSum(houseMoneyFlowT);
            houseMoneyFlowVO.setAreaName("合计");
            list.add(houseMoneyFlowVO);
        }
        ExcelUtil<HouseMoneyFlowT> util = new ExcelUtil<HouseMoneyFlowT>(HouseMoneyFlowT.class);
        util.exportExcel(response, list, "返还数据");
    }



    /**
     * 查询缴费明细
     */
    @GetMapping("/listCostQuery")
    public TableDataInfo listCostQuery(HouseMoneyFlowT houseMoneyFlowT) throws Exception {
        startPage();
        List<HouseMoneyFlowT> list = houseMoneyFlowTService.selectHouseCostDetailList(houseMoneyFlowT);
        for(HouseMoneyFlowT houseDoorVO :list){
            if(houseDoorVO.getUserName()!=null){
                houseDoorVO.setUserName(MD5.decrypt(houseDoorVO.getUserName()));
            }
        }
        return getDataTable(list);
    }
    /**
     * 查询维修明细
     */
    @GetMapping("/listRepairQuery")
    public TableDataInfo listRepairQuery(HouseMoneyFlowT houseMoneyFlowT) throws Exception {
        startPage();
        List<HouseMoneyFlowT> list = houseMoneyFlowTService.selectHouseRepairDetailList(houseMoneyFlowT);
        for(HouseMoneyFlowT houseDoorVO :list){
            if(houseDoorVO.getUserName()!=null){
                houseDoorVO.setUserName(MD5.decrypt(houseDoorVO.getUserName()));
            }
        }
        return getDataTable(list);
    }
    /**
     * 查询利息明细
     */
    @GetMapping("/listRateQuery")
    public TableDataInfo listRateQuery(HouseMoneyFlowT houseMoneyFlowT) throws Exception {
        startPage();
        List<HouseMoneyFlowT> list = houseMoneyFlowTService.selectHouseRateDetailList(houseMoneyFlowT);
        for(HouseMoneyFlowT houseDoorVO :list){
            if(houseDoorVO.getUserName()!=null){
                houseDoorVO.setUserName(MD5.decrypt(houseDoorVO.getUserName()));
            }
        }
        return getDataTable(list);
    }

}
